package com.example.mybatis.datasource;

import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource;
import org.springframework.lang.Nullable;
import org.springframework.stereotype.Component;

/**
 * @Author: zll
 * @Date @{DATE} 17:54
 * 返回当前 线程绑定的 数据源key
 */
public class DynamicDataSource extends AbstractRoutingDataSource{

    @Override
    protected Object determineCurrentLookupKey() {
        String dataSourceType = DatabaseContextHolder.getDataSourceType();
        System.out.println("动态获取到的 数据源key == "+dataSourceType);
        return dataSourceType;
    }
}
